/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bsc.war.form;

import bsc.ejb.entity.ScoreCardRelation;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class DeleteScoreCardRelation extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

            ModelAndView mav = null;
            System.out.println("ID1: "+request.getParameter("idScoreCard")+ " ID2: " +request.getParameter("idOtherScoreCard"));
        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");

            if (NumberUtils.isDigits(request.getParameter("idScoreCard"))
                    && NumberUtils.isDigits(request.getParameter("idOtherScoreCard")))
            {
                ScoreCardRelation rel = delegate.findScoreCardRelation(Long.parseLong(request.getParameter("idScoreCard")),
                        Long.parseLong(request.getParameter("idOtherScoreCard")));
                if(rel!=null) delegate.deleteScoreCardRelation(rel);
            }
        } catch (Exception e) {
            System.err.println("Caught exception: "+e);
            e.printStackTrace();
        }
        return mav;

    }

}
